<template>
	<view class="">
		<u-sticky bgColor="#fff">
			
					<u-navbar :fixed="true" :placeholder="true" title="设备清单" @leftClick="leftClick" bgColor="#0F53AC"
						leftIconColor="#fff">
					</u-navbar>
			<view class="help-pubuBox">
				<u-search placeholder="搜索设备名称或编号" :clearabled="true" height="40" shape="square" color="#2B2B2B"
					v-model="title" @search="chaxun" @change="chaxun" @custom="$dianji(cancel,'onoff')"
					:inputStyle="inputStyle" :actionStyle="actionStyle" :showAction="false"></u-search>
			</view>
			<view class="dropdown" v-if="showDropdown">
				<zb-dropdown-menu :zIndex="89" active-color="#0F53AC">
					<zb-dropdown-item :options="useOption" v-model="useValue" @change="(e)=>{handleSelect(e,1)}"
						name="first">
					</zb-dropdown-item>
					<zb-dropdown-item v-if="useValue==0" :options="eqOption" v-model="eqValue"
						@change="(e)=>{handleSelect(e,2)}" name="two">
					</zb-dropdown-item>
				</zb-dropdown-menu>
			</view>
		</u-sticky>
		<view class="eqList-box">
			<view class="eqList" v-for="eq in eqDataList" :key="eq.id">
				<view class="title">
					<view class="name">
						{{eq.deviceName}}
					</view>
					<view :class="useValue==1?'wx-type type':eq.deviceStatus==1?'use-type type':eq.deviceStatus==2?
						'wx-type type':eq.deviceStatus==3?'wb-type type':eq.deviceStatus==4?'dj-type type':'type'">
						{{useValue==1?'已停用':eq.deviceStatus==1?'使用中':eq.deviceStatus==2?'维修中':eq.deviceStatus==3?'维保中':eq.deviceStatus==4?'点检中':''}}
					</view>
				</view>
				<view class="info">
					<image :src="eq.devicePicture||'../../../static/images/index/weibaorenwu.png'" mode=""></image>
					<view class="text">
						<view class="right-info">
							<view class="info-name">
								设备类型：
							</view>
							<view class="info-text">
								{{eq.deviceTypeName}}
							</view>
						</view>
						<view class="right-info">
							<view class="info-name">
								设备编号：
							</view>
							<view class="info-text">
								{{eq.deviceNum}}
							</view>
						</view>
						<view class="right-info">
							<view class="info-name">
								所在部门：
							</view>
							<view class="info-text">
								{{eq.deptName}}
							</view>
						</view>
					</view>
				</view>
				<u-gap height="1" bgColor="#f2f2f2"></u-gap>
				<view class="item-btn" v-if="useValue!=1">
					<view class="chuku" @click="gotoDetail(eq.id)">查看详情</view>
					<!-- <text class="xian">|</text> -->
					<u-line direction="col" length="48rpx" />
					<view class="ruku" @click="editEquipment(eq.id)">编辑</view>
				</view>
				<view class="item-btn" v-else>
					<view class="ruku" @click="gotoDetail(eq.id)">查看详情</view>
				</view>
			</view>
			<u-loadmore v-if="total>5" :status="status" :line="true" />
			<view class="empty-data" v-if="eqDataList.length==0">
				<u-empty mode="data" :marginTop="100"></u-empty>
			</view>
		</view>
		<view class="fixed-btn" @click="addEquipment">
			<view class="btn-icon">
				<image src="../../../static/images/index/weiwai.png"></image>
			</view>
			<view class="btn-txt">创建设备</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showDropdown: true,
				//搜索值
				title: '',
				//按钮样式
				actionStyle: {
					color: '#0F53AC',
					fontSize: "32rpx",
				},
				inputStyle: {
					fontSize: '32rpx',
				},
				//使用状态option
				useOption: [{
						text: '在用设备',
						value: 0
					},
					{
						text: '停用设备',
						value: 1
					},
				],
				useValue: 0,
				//设备状态option
				eqOption: [{
						text: '设备状态',
						value: ''
					},
					{
						text: '使用中',
						value: 1
					},
					{
						text: '维修中',
						value: 2
					},
					{
						text: '维保中',
						value: 3
					},
					{
						text: '点检中',
						value: 4
					},
				],
				eqValue: '',
				//设备数据列表
				eqDataList: [],

				page: 1,
				total: 0,
				status: 'loadmore',
				//接口请求数据
				params: {
					pn: 1,
					ps: 5,
					keyword: '',
					stopFlag: 0, //0否1是	
					deviceStatus: '' //1.使用中； 2.维修中； 3.维保中； 4.点检中；
				},
				onoff: true,
			}
		},
		onLoad(options) {
			//请求之前先清空数据
			this.eqDataList = []
			//这里根据不同的状态值查询不同的结果
			if (options) {
				if (options.useType || options.eqType) {
					this.showDropdown = false
					this.params.pn = 1
					this.params.stopFlag = options.useType != 'undefined' ? options.useType : '0'
					this.params.deviceStatus = options.eqType != 'undefined' ? options.eqType : ''
					this.useValue = options.useType
				}
			}
			this.getDeviceList()
		},
		//下拉加载更多
		onReachBottom() {
			if (this.params.pn >= this.pages) return;
			this.status = 'loading';
			this.params.pn = ++this.params.pn;
			setTimeout(() => {
				this.getDeviceList()
				if (this.params.pn >= this.pages) this.status = 'nomore';
				else this.status = 'loading';
			}, 1000)
		},
		methods: {
			//1.获取列表
			getDeviceList() {
				console.log('this.params', this.params)
				uni.$u.http.post(`/device/mobile/deviceInfo/mobileDeviceList`, this.params).then(res => {
					if (res.code == 0) {
						this.eqDataList = this.eqDataList.concat(res.data.records);
						this.pages = res.data.pages;
						this.total = res.data.total;
					}
				}).catch(err => {
					uni.$u.toast(err)
				})
			},
			//2.搜索功能
			//change
			chaxun() {
				//清空数据
				this.total = 0
				this.eqDataList = []
				this.params.pn = 1
				this.params.keyword = this.title
				this.getDeviceList()
			},
			//cancel
			cancel() {
				this.title = ''
				this.total = 0
				this.eqDataList = []
				this.params.pn = 1
				this.params.keyword = ''
				this.getDeviceList()
			},


			//3.下拉选择 
			handleSelect(e, type) {
				//清空数据
				this.total = 0
				this.eqDataList = []
				this.params.pn = 1
				//传参
				if (type == 1) {
					this.eqValue = ''
					this.params.deviceStatus = ''
					this.params.stopFlag = e.value
				} else if (type == 2) {
					this.params.deviceStatus = e.value
				}
				//查询表单
				this.getDeviceList()
			},
			//去往详情
			gotoDetail(id) {
				uni.navigateTo({
					url: '/pages/subPackagesA/saoma/saomalist?id=' + id
				})
			},
			//编辑
			editEquipment(id) {
				uni.navigateTo({
					url: '/pages/subPackagesC/equipmentList/addEquipment?id=' + id
				})
			},
			//添加设备
			addEquipment() {
				uni.navigateTo({
					url: '/pages/subPackagesC/equipmentList/addEquipment'
				})
			},
			//点击返回按钮
			leftClick() {
				uni.switchTab({
					url: '/pages/work/index'
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: rgba(242, 242, 242, 1);
	}
	
	.item-btn {
		display: flex;
		justify-content: space-around;
		align-items: center;
		padding: 24rpx 0 0;
		background: #fff;
	
		.chuku {
			width: 45%;
			font-size: 32rpx;
			color: #666666;
			text-align: center;
		}
	
		.ruku {
			width: 45%;
			font-size: 32rpx;
			color: #0F53AC;
			text-align: center;
		}
	
		.su-line {
			width: 4rpx;
			height: 50rpx;
			background: #f2f2f2;
		}
	}
	
	.help-pubuBox {
		padding: 28rpx 32rpx;
		background: #fff;
	}
	
	.dropdown {
		border-top: 1px solid #EDEDED;
		// border-bottom: 1px solid rgba(242, 242, 242, 1);
	}
	
	.eqList-box {
	
		.eqList {
			padding: 32rpx;
			background-color: #fff;
			border-top: 1px solid #EDEDED;
	
			.title {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin-bottom: 24rpx;
	
				.name {
					width: 560rpx;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					text-align: left;
					font-size: 16px;
					font-weight: 500;
					color: #2B2B2B;
				}
	
				.type {
					// width: 96rpx;
					// height: 48rpx;
					text-align: center;
					// line-height: 48rpx;
					font-size: 12px;
					padding: 8rpx 24rpx;
					border-radius: 4px;
				}
	
				.use-type {
					color: rgba(2, 173, 130, 1);
					background: rgba(2, 173, 130, 0.2);
				}
	
				.wx-type {
					background: rgba(252, 119, 10, 0.2);
					color: rgba(252, 119, 10, 1);
				}
	
				.wb-type {
					background: rgba(15, 83, 172, 0.2);
					color: rgba(15, 83, 172, 1);
				}
	
				.dj-type {
					background: rgba(25, 98, 224, 0.2);
					color: rgba(25, 98, 224, 1);
				}
			}
	
			.info {
				display: flex;
				margin-bottom: 24rpx;
	
				image {
					width: 152rpx;
					height: 152rpx;
					border-radius: 16rpx;
				}
	
				.text {
					padding-left: 24rpx;
	
					.right-info {
						height: 48rpx;
						display: flex;
						align-items: center;
						justify-content: start;
	
						.info-name {
							font-size: 16px;
							font-weight: 400;
							color: #8C8C8C;
						}
	
						.info-text {
							font-size: 16px;
							font-weight: 400;
							color: #4D4D4D;
							width: 300rpx;
							overflow: hidden;
							white-space: nowrap;
							text-overflow: ellipsis;
						}
					}
				}
			}
		}
	}
	
	.u-empty .u-icon {
		z-index: -1;
	}
	
	.fixed-btn {
		position: fixed;
		bottom: 200rpx;
		right: 20rpx;
		z-index: 99;
		width: 160rpx;
		height: 160rpx;
		opacity: 1;
		background: rgba(15, 83, 172, 1);
		box-shadow: 0px 2px 6px rgba(10, 61, 128, 0.4);
		border-radius: 50%;
		font-size: 28rpx;
		display: flex;
		align-items: center;
		flex-direction: column;
		color: #fff;
	
		.btn-icon {
			margin-top: 25rpx;
	
			image {
				width: 52rpx;
				height: 52rpx;
			}
		}
	}
	
</style>
	
	